package wait;

public class Eat {
    private static Object object = "勺子";
    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 5; i++) {
                    synchronized (object) {
                        object.notify();
                        System.out.println(Thread.currentThread().getName() + "吃了" + i + "口");
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        },"杨过").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 5; i++) {
                    synchronized (object) {
                        object.notify();
                        System.out.println(Thread.currentThread().getName() + "吃了" + i + "口");
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        },"小龙女").start();


    }
}
